<?php
	session_start();

	if(isset($_SESSION['authorised']) && $_SESSION['authorised'] == true)
	{   
    	if(isset($_SESSION['type']))
    	{
        	if($_SESSION['type'] == 'administrator')
        	{
            	header('Location: admin_index.php');
            	exit();
        	}
		    elseif($_SESSION['type'] == 'student')
		     {
		        header('Location: student_index.php');
		        exit();
		    }
		    elseif($_SESSION['type'] == 'tutor')
		    {
		        header('Location: tutor_index.php');
		        exit();
		    }
		    elseif($_SESSION['type'] == 'parent')
		    {
		    $host = 'localhost';
			$dbuser = 'postgres';
			$dbpass = 'password';
			$dbname = $_SESSION['database'];
			$username = $_SESSION['user'];
			
			pg_connect("host=$host user=$dbuser password=$dbpass dbname=$dbname") or die(pg_last_error());
			
			?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Reservations</title>
<link href="StyleSheet.css" rel="stylesheet" type="text/css" />
<style>
.nav {
	width: 210px;
	height: auto;
	margin-left: 10px;
	text-align: center;
}

.mainline {
	width: 712px;
	height: auto;
	text-align: center;
}
</style>
</head>

<body bgcolor="#FFFFFF">
	<center>
		<div id="wrapper">
			<div id="header">
				<h1></h1>
			</div>

			<div id="header2">
				<h3></h3>
			</div>

			<div id="nav">
				<?php include 'parent_navigation.php';?>
			</div>

			<div id="mainline">
				<h4>Feedback from Tutors</h4>
			

			<div id="body">
				<form action="parent_deletefeedback.php" method="post">
				<center>
					<table width="700" height="auto" cellpadding="3" cellspacing="1" align="center">
				        <tr height="40" bgcolor="LightSteelBlue">
				            <th>Date / Time</th>
				            <th>From</th>
				            <th>Feedback</th>
				           
				        </tr>
						<?php
						
			            $sql = "SELECT student_evaluations.eval_date, student_evaluations.evaluation, student_evaluations.teacher_id, student_evaluations.student_id from student_evaluations where student_id in (select student_id from students where parent_id in (select parent_id from parents where username='$username')) "; 
			            $result = pg_query($sql);
			            
			            $count = pg_num_rows($result); 
			            if($count<1)
			            {
			            	echo "</table>";
			            	echo "<br>No feedbacks.";
			            }
			            else
			            {
				            for($i = 0; $i < $count; $i++)
				            {
				               $tutor = pg_fetch_result($result, $i, 'teacher_id');
				               $student = pg_fetch_result($result, $i, 'student_id');
				               $timestamp = pg_fetch_result($result, $i, 'eval_date');
				               $time = date_create_from_format('Y-m-d G:i:s.u', $timestamp);
				               $date= date_format($time, 'M-d-Y \a\t g:i a');
				               $evaluation = pg_fetch_result($result, $i, 'evaluation');
				               $sql2 = "SELECT * FROM teachers natural join users where teacher_id='$tutor'";
		           			   $result1 = pg_query($sql2);
		           			   $tutor_lastname = pg_fetch_result($result1, 0, 'lastname');
		           			   $tutor_firstname = pg_fetch_result($result1, 0, 'firstname');
		           			   $sql2 = "SELECT * FROM students natural join users where student_id='$student'";
		           			   $result1 = pg_query($sql2);
		           			   $student_firstname = pg_fetch_result($result1, 0, 'firstname');
				               
				               echo '<tr bgcolor="#f5f5f5">
				                        <td>'.$date. '</td>
				                        <td>'.$tutor_lastname.", ".$tutor_firstname. '</td>
				                        <td>'.'Evaluation for: '.$student_firstname."<br><br>$evaluation</td></tr>";
				            }
				            echo "</table> ";
			            }
						?>
				</center>
			</div>

			<p align="justify">
				<br />
			</p>
		</div>

		<br class="clearfloat"> <br />

		<div id="footer">
			<p align="center">
				Tutorial Business Manager: info@tbms.com <br />Credits/Engineers:
				Aquino, Chloebelle; Dela Cruz, Roy Erwin; Maliwanag, Ranyel Bryan;
				Manzano, Audrey Ann; Ng, Sheila Regine<br /> <br />copyright 2011
			</p>
		</div>
		</div>
	</center>
</body>
</html>
<?php
			}
   	 	}
	}
	else
	{
  		header('Location: index.php');
	}
?>
